#include <iostream>
#include <memory>

using std::unique_ptr;
using std::cout;
using std::endl;

class Component
{
public:
    virtual void operation() = 0;
    virtual ~Component(){}
};

class ConcreteComponent
:public Component
{
public:
    void operation()
    {
        cout << "ConcreteComponent具体操作" << endl;
    }
};

class Decorator
:public Component
{
public:
    void setComponent(Component *ptr)
    {
        _pcom = ptr;
    }

    virtual void operation()
    {
        if(_pcom != nullptr)
        {
            _pcom->operation();
        }
    }

private:
    Component * _pcom;
};

class ConcreteDecoratorA
:public Decorator
{
public:
    void operation()
    {
        Decorator::operation();
        achieve();
    }
    void achieve()
    {
        cout << "ConcreteDecoratorA" << endl;
    }

};

class ConcreteDecoratorB
:public Decorator
{
public:
    void operation()
    {
        Decorator::operation();
        achieve();
    }
    void achieve()
    {
        cout << "ConcreteDecoratorB" << endl;
    }

};

void test(){
    unique_ptr<Decorator> pda(new ConcreteDecoratorA());
    unique_ptr<Decorator> pdb(new ConcreteDecoratorB());
    unique_ptr<Component> pc(new ConcreteComponent());



}

int main()
{
    test();
    return 0;
}

